import React, { Component } from 'react';
import PropTypes from 'prop-types';

import {Grid, Nav, NavItem, Row} from 'react-bootstrap';

export default class MenuPage extends Component {
    static propTypes = {
        menuMap:PropTypes.object,
    };

    // constructor(props, context) {
    //     super(props, context);
    // }

    handleSelect(selectedKey) {
        window.childPage = selectedKey;
        this.subFrame.contentWindow.location.reload(true);
    }

    render() {
        let navs = [];
        for (let key in this.props.menuMap){
            navs.push(<NavItem eventKey={key} key={key} href="#">
                {this.props.menuMap[key]}
            </NavItem>);
        }
        return (
            <Grid>
                <Row><Nav bsStyle="pills" onSelect={this.handleSelect.bind(this)}>{navs}</Nav></Row>
                <Row>
                    <iframe title="Inner Frame" ref={ref=>this.subFrame=ref} src="#" width="100%" height="100%" style={{minHeight:"600px"}}></iframe>
                </Row>
            </Grid>
        );
    }
}

MenuPage.defaultProps={
    menuMap:{}
};

